﻿Imports BE.BE

Namespace DAL
    Public Class DAL_Expediente

        Shared Sub guardar(pExpediente As Expediente_BE)


            Try
                pExpediente.IdExpediente = Helper_DAL.ObtenerProximoId("expediente")
            Catch ex As Exception
                Throw ex
            End Try

            Dim strcomm As String = "insert into expediente (id_expediente, numero_expediente, rubro, siniestro, id_cliente, id_contraparte, id_abogadoEstudio, id_abogadoAseguradora, polizaCliente, polizaContraparte) values " & _
                "(" & pExpediente.IdExpediente & "," & pExpediente.NumeroExpediente & ",'" & pExpediente.Rubro & "','" & pExpediente.Siniestro & "'," & pExpediente.Cliente.Id & "," & pExpediente.Contraparte.IdContraparte & "," & pExpediente.AbogadoEstudio.IdAbogadoEstudio & "," & pExpediente.AbogadoAseguradora.IdAbogadoAseguradora & ",'" & pExpediente.PolizaCliente & "','" & pExpediente.PolizaContraparte & "')"

            Try
                Helper_DAL.ExecuteNonQuery(strcomm)

            Catch ex As Exception
                Throw ex
            End Try



        End Sub

        Shared Sub modificar(pExpediente As Expediente_BE)


        End Sub

        Shared Function listarExpediente() As List(Of Expediente_BE)
            Dim strcomm As String = "select id_expediente, numero_expediente, rubro, siniestro, id_cliente, id_contraparte, id_abogadoEstudio, id_abogadoAseguradora, polizaCliente, polizaContraparte from expediente"
            Dim mds As New DataSet
            Dim mlista As New List(Of Expediente_BE)

            Try
                mds = Helper_DAL.ExecuteDataset(strcomm)

                If mds.Tables(0).Rows.Count > 0 Then
                    For Each dr As DataRow In mds.Tables(0).Rows
                        Dim mexp As New Expediente_BE
                        Dim mcli As New Cliente_BE
                        Dim mcontra As New Contraparte_BE
                        Dim maboest As New AbogadoEstudio_BE
                        Dim maboasef As New AbogadoAseguradora_BE

                        mexp.IdExpediente = dr.Item(0)
                        mexp.NumeroExpediente = dr.Item(1).ToString
                        mexp.Rubro = dr.Item(2).ToString
                        mexp.Siniestro = dr.Item(3).ToString
                        mcli.IdCliente = dr.Item(4)
                        mexp.Cliente = mcli
                        mcontra.IdContraparte = dr.Item(5)
                        mexp.Contraparte = mcontra
                        maboest.IdAbogadoEstudio = dr.Item(6)
                        mexp.AbogadoEstudio = maboest
                        maboasef.IdAbogadoAseguradora = dr.Item(7)
                        mexp.AbogadoAseguradora = maboasef
                        mexp.PolizaCliente = dr.Item(8).ToString
                        mexp.PolizaContraparte = dr.Item(9).ToString

                        mlista.Add(mexp)

                    Next
                End If

                Return mlista
            Catch ex As Exception
                Throw ex
            End Try
        End Function
    End Class
End Namespace

